home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / _truncdf.cpp < prev    next >
Text File  |  1992-03-30  |  2KB  |  106 lines

  1. | not needed with -__M68881__
  2.  
  3. #ifndef    __M68881__
  4. # ifdef    sfp004
  5.  
  6. | double float to single float conversion routine
  7. | oflow checking is omitted. The ''881 returns a signed infinity.
  8. |
  9. | Written by M.Ritzert
  10. | 5.10.90
  11. | ritzert@dfg.dbp.de
  12. |
  13.  
  14. | addresses of the 68881 data port. This choice is fastest when much data is
  15. | transferred between the two processors.
  16.  
  17. comm =     -6
  18. resp =    -16
  19. zahl =      0
  20.  
  21. | waiting loop ...
  22. |
  23. | wait:
  24. | ww:    cmpiw    #0x8900,a1@(resp)
  25. |     beq    ww
  26. | is coded directly by
  27. |    .long    0x0c688900, 0xfff067f8
  28.  
  29.     .text
  30.     .even
  31.     .globl    __truncdfsf2, ___truncdfsf2
  32.  
  33. __truncdfsf2:
  34. ___truncdfsf2:
  35.     lea    0xfffa50,a0
  36.     movew    #0x5400,a0@(comm)    | load double to  fp0
  37.     cmpiw    #0x8900,a0@(resp)    | check
  38.     movel    a7@(4),a0@        | push arguments
  39.     movel    a7@(8),a0@        |
  40.     movew    #0x6400,a0@(comm)    | result (real) to d0
  41.     .long    0x0c688900, 0xfff067f8
  42.     movel    a0@,d0
  43.     rts
  44.  
  45. # else    sfp004
  46.  
  47. | double float to single float conversion routine
  48. |
  49. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  50. | Based on a 80x86 floating point packet from comp.os.minix, written by P.Housel
  51. |
  52. |
  53. | Revision 1.2, kub 01-90 :
  54. | added support for denormalized numbers
  55. |
  56. | Revision 1.1, kub 12-89 :
  57. | Ported over to 68k assembler
  58. |
  59. | Revision 1.0:
  60. | original 8088 code from P.S.Housel
  61.  
  62. BIAS4    =    0x7F-1
  63. BIAS8    =    0x3FF-1
  64.  
  65.     .text
  66.     .even
  67.     .globl    __truncdfsf2, ___truncdfsf2
  68.  
  69. __truncdfsf2:
  70. ___truncdfsf2:
  71.     lea    sp@(4),a0    | parameter pointer
  72.     moveml    d2-d5,sp@-    | save regs
  73.     moveml    a0@,d4-d5    | get number
  74.  
  75.     movew    a0@,d0        | extract exponent
  76.     movew    d0,d2        | extract sign
  77.     lsrw    #4,d0
  78.     andw    #0x7ff,d0    | kill sign bit
  79.  
  80.     andl    #0x0fffff,d4    | remove exponent from mantissa
  81.     tstw    d0        | check for zero exponent - no leading "1"
  82.     beq    0f        | for denormalized numbers
  83.     orl    #0x100000,d4    | restore implied leading "1"
  84.     bra    1f
  85. 0:    addw    #1,d0        | "normalize" exponent
  86. 1:
  87.     addw    #BIAS4-BIAS8,d0    | adjust bias
  88.  
  89.     addl    d5,d5        | shift up to realign mantissa for floats
  90.     addxl    d4,d4
  91.     addl    d5,d5
  92.     addxl    d4,d4
  93.     addl    d5,d5
  94.     addxl    d4,d4
  95.  
  96.     movel    d5,d1        | set rounding bits
  97.     roll    #8,d1
  98.     andl    #0x00ffffff,d5    | check to see if sticky bit should be set
  99.     beq    2f
  100.     orb    #1,d1        | set sticky bit
  101. 2:
  102.     jmp    norm_sf        | (leave regs on stack for norm_sf)
  103.  
  104. # endif    sfp004
  105. #endif    __M68881__
  106.